package org.jeecg.modules.flow.sys.enumx;


import cn.hutool.core.util.ObjectUtil;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/*
 * 项目名称:    wms-server-jeecg
 * 接口描述:    单个流程节点的状态
 *            》 -2 中止 -1 失败 0 无状态；1 执行中；200 成功；；3 跳过；
 * 创建人员:    zhaojun
 * 创建时间:    2023-09-14
 */
public enum FlowRecordStatusEnum {
    INTERRUPT(-2, "中止"),
    FAIL(-1, "失败"),
    NOSTATUS(0, "无状态"),
    EXECUTING(1, "执行中"),
    PAUSE(2, "暂停"),
    JUMP(3, "跳过"),
    SUCCESS(200, "成功");


    private Integer code;
    private String msg;

    FlowRecordStatusEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static List<FlowRecordStatusEnum> getAllObjects() {
        return Arrays.stream(FlowRecordStatusEnum.values())
                .collect(Collectors.toList());
    }

    public static String getName(Integer code) {
        if (ObjectUtil.isEmpty(code)) {
            return "";
        }
        List<FlowRecordStatusEnum> recordStatusEnums = getAllObjects();
        for (FlowRecordStatusEnum flowRecordStatusEnum : recordStatusEnums) {
            if (flowRecordStatusEnum.getCode().equals(code)) {
                return flowRecordStatusEnum.getMsg();
            }
        }
        return "";
    }


    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
